package my.poemhelper.bo;

import my.poemhelper.dao.PoemDao;
import my.poemhelper.vo.PageControl;
import my.poemhelper.vo.Poem;
import my.poemhelper.vo.PoemAnaly;
import my.poemhelper.vo.PoemCheck;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PoemBoImpl implements PoemBo {
	
	@Autowired
	private PoemDao peomDao;

	@Override
	public void insertPeom(Poem p) {
		peomDao.insertPeom(p);
	}

	@Override
	public void delPeom(long id) {
		peomDao.delPeom(id);
	}

	@Override
	public void queryPoemByWord(String w,PageControl<Poem> pc) {
		peomDao.queryByWord(w, pc);
	}

	@Override
	public void doPoemAnaly(PoemAnaly pa) {
		//结构特征 4句==》绝句
		//8句为律
		//5个字为五言 7个字为七言
		StringBuilder struture = new StringBuilder();
		String content = pa.getContent();
		int index = content.indexOf("，");
		if(index==5){
			struture.append("五");
		}else if(index==7){
			struture.append("七");
		}
		String[] ss = content.split("。");
		if(ss.length==2){
			struture.append("绝");
		}else if(ss.length==4){
			struture.append("律");
		}
		if(struture.length()!=2){
			struture = new StringBuilder("未知结构");
		}
		pa.setStructure(struture.toString());
		peomDao.doPoemAnaly(pa);
	}

	@Override
	public void doPoemCheck(PoemCheck pc) {
		peomDao.doPoemCheck(pc);
	}

}
